<template>
  <div class="user-container">
    <!-- 登陆区域 -->
    <van-row class="login">
      <van-col span="6">
        <img :src="imgsrc" alt="" />
      </van-col>
      <van-col span="18"
        ><span @click="login">{{ this.loginmsg }}</span>
        <div @click="ModifyInformation">修改个人信息</div></van-col
      >
    </van-row>
    <!-- 我的订单区域 -->
    <div class="myorder">
      <!-- 第一行 -->
      <div class="top">
        <span>我的订单</span>
        <span><van-icon name="arrow"/></span>
      </div>
      <!-- 第二行 -->
      <div class="bottom">
        <div>
          <div><van-icon class-prefix="iconfont icon-daifukuan" /></div>
          <div>代付款</div>
        </div>
        <div>
          <div><van-icon class-prefix="iconfont icon-daifahuo" /></div>
          <div>代发货</div>
        </div>
        <div>
          <div>
            <van-icon class-prefix="iconfont icon-daishouhuofuben" />
          </div>
          <div>代收货</div>
        </div>
        <div>
          <div><van-icon class-prefix="iconfont icon-daipingjia" /></div>
          <div>代评价</div>
        </div>
        <div>
          <div><van-icon class-prefix="iconfont icon-shouhou" /></div>
          <div>售后</div>
        </div>
      </div>
    </div>
    <!-- 核心服务区域 -->
    <div class="myorder">
      <!-- 第一行 -->
      <div class="top">
        <span>我的订单</span>
        <span><van-icon name="arrow"/></span>
      </div>
      <!-- 第二行 -->
      <div class="bottom">
        <div>
          <div><van-icon class-prefix="iconfont icon-wodeyouhuijuan" /></div>
          <div>优惠卷</div>
        </div>
        <div @click="goodsCollection">
          <div><van-icon class-prefix="iconfont icon-jiaxingshoucang" /></div>
          <div>商品收藏</div>
        </div>
        <div>
          <div>
            <van-icon class-prefix="iconfont icon-zuji" />
          </div>
          <div>浏览足迹</div>
        </div>
        <div>
          <div><van-icon class-prefix="iconfont icon-pintuan" /></div>
          <div>我的拼团</div>
        </div>
        <div>
          <div><van-icon class-prefix="iconfont icon-floor-building" /></div>
          <div>地址管理</div>
        </div>
      </div>
    </div>
    <!-- 必备工具区域 -->
    <div class="myorder">
      <!-- 第一行 -->
      <div class="top">
        <span>我的订单</span>
        <span><van-icon name="arrow"/></span>
      </div>
      <!-- 第二行 -->
      <div class="bottom">
        <div>
          <div><van-icon class-prefix="iconfont icon-shouji" /></div>
          <div>绑定手机</div>
        </div>
        <div>
          <div><van-icon class-prefix="iconfont icon-duowenjian" /></div>
          <div>帮助中心</div>
        </div>
        <div>
          <div>
            <van-icon class-prefix="iconfont icon-yijianfankui" />
          </div>
          <div>意见反馈</div>
        </div>
        <div>
          <div><van-icon class-prefix="iconfont icon-lianxikefu" /></div>
          <div>联系客服</div>
        </div>
        <div>
          <div><van-icon class-prefix="iconfont icon-guanyuwomen" /></div>
          <div>关于我们</div>
        </div>
      </div>
    </div>

    <!-- 退出登录区域 -->
    <div class="loginout">
      <span @click="loginout">退出登录</span>
    </div>
  </div>
</template>

<script>
export default {
  name: 'YanxuanshangchengUser',
  data() {
    return {
      imgsrc: '/static/logo.png',
      loginmsg: '未登录',
      // 用户的缓存信息
      username: {}
    }
  },
  created() {
    // 获取用户信息
    this.getusername()
  },
  methods: {
    // 获取用户信息
    getusername() {
      let userInfo = JSON.parse(this.$cookie.get('username'))
      // console.log(userInfo)
      this.username = userInfo
      // console.log(this.username)
      this.loginmsg = this.username.nickname
      this.imgsrc = this.username.avatar
    },
    // 登录
    login() {
      this.$router.push('/login')
    },
    // 退出登录
    loginout() {
      this.$post(this.$api.authLogout)
        .then(result => {
          console.log(result)
          if (result.data.errno == 501) {
            return console.log('退出错误')
          }
          this.$cookie.remove('token')
          this.$cookie.remove('username')
          location.reload()
          console.log(result)
        })
        .catch(err => {
          console.log(err)
        })
    },
    // 修改用户个人信息
    ModifyInformation() {
      this.$router.push('/modifyinformation')
    },
    // 前往商品收藏页
    goodsCollection() {
      // console.log(1)
      this.$router.push({ name: 'goodsCollection' })
    }
  }
}
</script>

<style lang="less" scoped>
// 登陆区域
.login {
  padding: 1rem;
  display: flex;
  align-items: center;
  height: 10rem;
  color: #fff;
  background-color: #ab956d;
  .van-col:nth-child(1) {
    margin-top: 1rem;
    font-size: 7rem;
    height: 9rem;
    text-align: center;
    border-radius: 50%;
  }
  img {
    border-radius: 50%;
    width: 100%;
    height: 100%;
  }

  span {
    margin-left: 1rem;
    font-size: 2rem;
  }
}
// 我的订单区域
.myorder {
  color: #000;
  height: 11.5rem;
  background-color: #fff;
  border: 0.1rem solid #ccc;
  > .top {
    margin-top: 1rem;
    padding: 0 1rem 0 1rem;
    display: flex;
    justify-content: space-between;
    > span:nth-child(1) {
      font-weight: 700;
    }
  }
  > .bottom {
    font-size: 1.2rem;
    margin-top: 1rem;
    display: flex;
    justify-content: space-between;
    height: 7rem;
    > div {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-around;
    }
    i {
      width: 100%;
      font-size: 2.5rem;
    }
  }
}

// 退出登录区域
.loginout {
  border: 0.1rem solid #f2f3f3;
  text-align: center;
  line-height: 5rem;
  width: 100%;
  height: 5rem;
  background-color: #fff;
}
</style>
